#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QThread>

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // 窗口属性设定
    this->setWindowTitle("五子棋-主界面");
    this->setFixedSize(400, 300);

    // 按钮功能设定
    connect(ui->btn_single_player, &QPushButton::clicked, this, &MainWindow::btn_single_player);
    connect(ui->btn_multi_player, &QPushButton::clicked, this, &MainWindow::btn_multi_player);
    connect(ui->btn_multi_player, &QPushButton::clicked, &multiPlayer, &MultiPlayer::create_client);// 多人游戏开始向服务器建立连接

    // 绑定信号
    connect(&singlePlayer, &SinglePlayer::back, this, &MainWindow::back_single_player); // 单人游戏返回主界面
    connect(&multiPlayer, &MultiPlayer::back, this, &MainWindow::back_multi_player);    // 多人游戏返回主界面
    connect(&multiPlayer, &MultiPlayer::quit, this, &MainWindow::quit);
}

MainWindow::~MainWindow()
{
    delete ui;
}

// 槽函数 单机模式按钮
void MainWindow::btn_single_player()
{
    this->hide();
    this->singlePlayer.show();
}

// 槽函数 多人模式按钮
void MainWindow::btn_multi_player()
{
    this->hide();
    this->multiPlayer.show();
}

// 槽函数 从单人游戏界面返回
void MainWindow::back_single_player()
{
    this->singlePlayer.close();
    this->show();
}

// 槽函数 从多人游戏界面返回
void MainWindow::back_multi_player()
{
    this->multiPlayer.close();
    this->show();
}

// 槽函数 退出游戏
void MainWindow::quit()
{
    this->multiPlayer.close();
    this->close();    
}



